#ifndef SHORTTCPCLIENT_H
#define SHORTTCPCLIENT_H

#include <QObject>
#include <QTcpSocket>

#include "netchannel.h"

enum E_TRANS_ERR_CODE{
    E_TRANS_SUCCESS,
    E_TRANS_CONNECT_FAIL,
    E_TRANS_SEND_FAIL,
    E_TRANS_RECV_TIMEOUT,
    E_TRANS_SEND_INVALID
};

class ShortTcpClient : public QObject
{
    Q_OBJECT
public:
    explicit ShortTcpClient(QObject *parent = nullptr);

    bool Init(const QString qsIP, int nPort);
    int TransForNormal(const PACKET_INFO pktInfo,const std::string& sReq, std::string& sRsp, QString& qsErrMsg);
protected:
    int PreSendHandle(std::shared_ptr<char> &sendEnBuf, const std::string sSend,const PACKET_INFO pktInfo);
    int SufRecvHandle(const char* pRecvBuf, unsigned int ulLen, std::string& sRsp,const PACKET_INFO pktInfo);
signals:

public slots:
    void ReadData();
    void ReadError(QAbstractSocket::SocketError);
private:
    std::shared_ptr<QTcpSocket> m_tcpClient;
    QString     m_qsIp;
    int         m_nPort;
    AuthChannel m_auChl;
    TradeChannel m_tradeChl;

};

#endif // SHORTTCPCLIENT_H
